﻿// Copyright (c) Microsoft Corporation.  All rights reserved. 
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace WiE.Model
{
    class MemberChangedArgs : DataObjectChangedArgs
    {
        public MemberChangedArgs() { }

        public MemberChangedArgs(WiEMemberDataObject p_memberDataObject) : base(p_memberDataObject) { }

        public MemberChangedArgs(WiEMemberDataObject p_memberDataObject, ChangeType p_changeType) : base(p_memberDataObject, p_changeType) { }

        WiEMemberDataObject MemberChanged
        {
            set { base.m_wieDataObject = value; }
            get { return (WiEMemberDataObject)base.m_wieDataObject; }
        }
    }

    class WiEMemberDataObject : WiEDataObject
    {
        // Property Key definitions when Member Data Object for use when object is converted into a property bag...
        public const string KEY_MEMBERID = "MemberID";
        public const string KEY_FIRSTNAME = "FirstName";
        public const string KEY_LASTNAME = "LastName";
        public const string KEY_EMAIL = "Email";
        public const string KEY_PHONENUMBER = "PhoneNumber";
        public const string KEY_USERNAME = "UserName";
        public const string KEY_PASSWORD = "Password";

        // Member / properties
        private System.Guid m_guidMemberID;
        private string m_strFirstName;
        private string m_strLastName;
        private string m_strEmail;
        private string m_strPhoneNumber;
        private string m_strUserName;
        private string m_strUserPassword;

        // constructors

        /// <summary>
        /// Default constructor
        /// </summary>
        public WiEMemberDataObject()
        {
        }

        /// <summary>
        /// Constructor for a new WiEMemberDataObject
        /// </summary>
        /// <param name="p_guidMemberID"></param>
        /// <param name="p_strFirstName"></param>
        /// <param name="p_strLastName"></param>
        /// <param name="p_strEmail"></param>
        /// <param name="p_strPhoneNumber"></param>
        /// <param name="p_strUserName"></param>
        /// <param name="p_strPassword"></param>
        public WiEMemberDataObject(System.Guid p_guidMemberID, string p_strFirstName, string p_strLastName, string p_strEmail, string p_strPhoneNumber, string p_strUserName, string p_strPassword)
        {
            m_guidMemberID = p_guidMemberID;
            m_strFirstName = p_strFirstName;
            m_strLastName = p_strLastName;
            m_strEmail = p_strEmail;
            m_strPhoneNumber = p_strPhoneNumber;
            m_strUserName = p_strUserName;
            m_strUserPassword = p_strPassword;
        }

        /// <summary>
        /// Returns unique id for this data object (member)
        /// </summary>
        public override Guid UniqueId
        {
            get { return m_guidMemberID; }
        }

        /// <summary>
        /// Construct and populate a WiE Member Data Object using a property bag of fields.
        /// </summary>
        /// <param name="p_propertyBag"></param>
        public WiEMemberDataObject(Dictionary<string, object> p_propertyBag)
        {
            foreach (KeyValuePair<string, object> kvp in p_propertyBag)
            {
                switch (kvp.Key)
                {
                    case KEY_MEMBERID:
                        m_guidMemberID = new Guid(kvp.Value.ToString());
                        break;
                    case KEY_FIRSTNAME:
                        m_strFirstName = kvp.Value.ToString();
                        break;
                    case KEY_LASTNAME:
                        m_strLastName = kvp.Value.ToString();
                        break;
                    case KEY_EMAIL:
                        m_strEmail = kvp.Value.ToString();
                        break;
                    case KEY_PHONENUMBER:
                        m_strPhoneNumber = kvp.Value.ToString();
                        break;
                    case KEY_USERNAME:
                        m_strUserName = kvp.Value.ToString();
                        break;
                    case KEY_PASSWORD:
                        m_strUserPassword = kvp.Value.ToString();
                        break;
                }
            }
        }

        /// <summary>
        /// The ID of the member
        /// </summary>
        public System.Guid MemberID
        {
            set { m_guidMemberID = value; }
            get { return m_guidMemberID; }
        }

        /// <summary>
        /// The first name of the member
        /// </summary>
        public string FirstName
        {
            set { m_strFirstName = value; }
            get { return m_strFirstName; }
        }

        /// <summary>
        /// The last name of the member
        /// </summary>
        public string LastName
        {
            set { m_strLastName = value; }
            get { return m_strLastName; }
        }

        /// <summary>
        /// The e-mail address associated with the member
        /// </summary>
        public string Email
        {
            set { m_strEmail = value; }
            get { return m_strEmail; }
        }

        /// <summary>
        /// The PhoneNumber for the member
        /// </summary>
        public string PhoneNumber
        {
            set { m_strPhoneNumber = value; }
            get { return m_strPhoneNumber; }
        }

        /// <summary>
        /// The UserName for the member
        /// </summary>
        public string UserName
        {
            set { m_strUserName = value; }
            get { return m_strUserName; }
        }

        /// <summary>
        /// The Password for the member (someday we may not want to send this back and forth).
        /// </summary>
        public string Password
        {
            set { m_strUserPassword = value; }
            get { return m_strUserPassword; }
        }

        /// <summary>
        /// Returns the object as a propery bag collection
        /// </summary>
        /// <returns></returns>
        public override Dictionary<string, object> ToPropertyDictionary()
        {
            Dictionary<string, object> dictionaryProperties = new Dictionary<string, object>();

            if (MemberID != null)
                dictionaryProperties.Add(KEY_MEMBERID, MemberID.ToString());

            if (FirstName != null)
                dictionaryProperties.Add(KEY_FIRSTNAME, FirstName);

            if (LastName != null)
                dictionaryProperties.Add(KEY_LASTNAME, LastName);

            if (Email != null)
                dictionaryProperties.Add(KEY_EMAIL, Email);

            if (PhoneNumber != null)
                dictionaryProperties.Add(KEY_PHONENUMBER, PhoneNumber);

            if (UserName != null)
                dictionaryProperties.Add(KEY_USERNAME, UserName);

            if (Password != null)
                dictionaryProperties.Add(KEY_PASSWORD, Password);
            
            return dictionaryProperties;
        }

    }
}
